home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Text / print / HPDJ900Src.lha / dospecial.c < prev    next >
C/C++ Source or Header  |  2004-05-21  |  10KB  |  290 lines

  1. /*
  2.  **************************************************************************
  3.  *
  4.  *       DoSpecial for HP_Deskjet_900C driver.
  5.  *       By PJ Hutchison 1/11/01
  6.  *
  7.  **************************************************************************
  8.  */
  9.  
  10. #include "global.h"
  11.  
  12. #define LPI             9    /* Position in init.. string from 0 - 7 */
  13. #define CPI             21
  14. #define CHARSET         32
  15. #define QUALITY         42
  16. #define ASPECT          47   /* Portrait or Landscape */
  17. #define TYPEFACE        52
  18. #define INIT_LEN        54
  19. #define LPP             10   /* Lines Per Page  */
  20. #define FORM_LEN        14
  21. #define LEFT_MARG       3
  22. #define RIGHT_MARG      10
  23. #define MARG_LEN        15
  24.  
  25. /* Version string */
  26.  
  27. const char __ver[39] = "$VER: HP_Deskjet_900C 40.14 (18.05.04)";
  28.  
  29. extern struct PrinterData *PD;
  30. extern struct PrinterExtendedData *PED;
  31.  
  32. /* Routine to handle complex Escape sequences */
  33.  
  34. int DoSpecial(UWORD *command, char outputBuffer[], BYTE *vline, BYTE *currentVMI, BYTE *crlfFlag, UBYTE Parms[])
  35. {
  36.        
  37.         static UWORD textlength, topmargin;
  38.         int x, y, j, papersize, lpi;
  39.  
  40.         static char initThisPrinter[INIT_LEN + 1] =
  41.                 "\033&l26A\033&l6D\033&d@\033(s0b10h0p0s12V\033(1E\033*v1S\033*o0M\033&l0O\033(s3T";
  42.                 
  43.                 /* 00-05 \033&l26A   = A4 Paper
  44.                    06-10 \033&l6D    = 6 Lines per inch (LPI)
  45.                    11-14 \033&d@     = Underline off
  46.                    15-19 \033(s0b    = Normal weight (Bold off)
  47.                    20-22      10h    = 10 chars per inch (CPI)
  48.                    23-24       0p    = Fixed spacing
  49.                    25-26       0s    = Upright style
  50.                    27-29      12V    = 12 points/inch
  51.                    30-33 \033(1E     = UK Char set (CHARSET)
  52.                    34-38 \033*v1S    = Black text
  53.                    39-43 \033*o0M    = Quality (QUALITY)
  54.                    44-48 \033&l0O    = Portrait (ASPECT)
  55.                    49-53 \033(s3T    = Typeface
  56.                 */
  57.         static char initForm[FORM_LEN + 1] = "\033&l000E\033&l000F";
  58.         static char initMarg[MARG_LEN + 1] = "\033&a000L\033&a000M\015";
  59.         static char initTMarg[] = "\033&l000E\033&l000F";
  60.        
  61.         static char ISOColorTable[11] = "0102116881";
  62.  
  63.         x = y = j = 0;
  64.  
  65.         if (*command == aRIN) {         /* Initialise command */
  66.                 while(x < INIT_LEN) {
  67.                         outputBuffer[x] = initThisPrinter[x];
  68.                         x++;
  69.                 }
  70.                 outputBuffer[x++] = '\015';
  71.                                
  72.                 lpi = 6;
  73.                 if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  74.                         outputBuffer[LPI] = '8';
  75.                         lpi = 8;
  76.                 }
  77.  
  78.                 if (PD->pd_Preferences.PrintPitch == ELITE) {
  79.                         outputBuffer[CPI] = '2';
  80.                 }
  81.                 else if (PD->pd_Preferences.PrintPitch == FINE) {
  82.                         outputBuffer[CPI] = '5';
  83.                 }
  84.                 if (PD->pd_Preferences.PrintQuality == LETTER) {
  85.                         outputBuffer[QUALITY] = '1';
  86.                 }
  87.                 /* Change to Landscape (Vert)) if selected) */
  88.                 if (PD->pd_Preferences.PrintAspect == ASPECT_VERT) {
  89.                             outputBuffer[ASPECT] = '1';
  90.                 }
  91.  
  92.                 j = x; /* set the formlength = textlength, top margin = 1 */
  93.                 papersize = PD->pd_Preferences.PaperSize;
  94.         switch (papersize) 
  95.         {
  96.            case US_LETTER:
  97.             papersize = 10 * lpi;
  98.             break;
  99.            case US_LEGAL:
  100.             papersize = 13 * lpi;
  101.             break;
  102.            case EURO_A4:
  103.             papersize = (lpi == 8 ? 85 : 65);
  104.             break;
  105.            default:   /* Custom size */
  106.             papersize = PD->pd_Preferences.PaperLength;
  107.         }
  108.                 textlength = papersize;
  109.                 topmargin = 1;
  110.  
  111.                 while (y < FORM_LEN) {
  112.                         outputBuffer[x++] = initForm[y++];
  113.                 }
  114.                 numberString(textlength, j + LPP, outputBuffer);
  115.  
  116.                 Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  117.                 Parms[1] = PD->pd_Preferences.PrintRightMargin;
  118.                 *command = aSLRM;
  119.         }
  120.  
  121.         if (*command == aSLRM) {        /* L&R Margins */
  122.                 j = x;
  123.                 y = 0;
  124.                 while(y < MARG_LEN) {
  125.                         outputBuffer[x++] = initMarg[y++];
  126.                 }
  127.                 numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  128.                 numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  129.                 return(x);
  130.         }
  131.  
  132.         if ((*command == aSUS2) && (*vline == 0)) { /* Superscript on */
  133.                 *command = aPLU; /* Partial line up */
  134.                 *vline = 1;
  135.                 return(0);
  136.         }
  137.  
  138.         if ((*command == aSUS2) && (*vline < 0)) {
  139.                 *command = aRI; /* Reverse LF */
  140.                 *vline = 1;
  141.                 return(0);
  142.         }
  143.  
  144.         if ((*command == aSUS1) && (*vline > 0)) {  /* Superscript off */
  145.                 *command = aPLD; /* Partial line down */
  146.                 *vline = 0;
  147.                 return(0);
  148.         }
  149.  
  150.         if ((*command == aSUS4) && (*vline == 0)) { /* Subscript on */
  151.                 *command = aPLD;
  152.                 *vline = -1;
  153.                 return(0);
  154.         }
  155.  
  156.         if ((*command == aSUS4) && (*vline > 0)) {
  157.                 *command = aIND; /* Line feed */
  158.                 *vline = -1;
  159.                 return(0);
  160.         }
  161.  
  162.         if ((*command == aSUS3) && (*vline < 0)) { /* Subscript off */
  163.                 *command = aPLU;
  164.                 *vline = 0;
  165.                 return(0);
  166.         }
  167.  
  168.         if(*command == aSUS0) {              /* Normalise the line */
  169.                 if (*vline > 0) {
  170.                         *command = aPLD;
  171.                 }
  172.                 if (*vline < 0) {
  173.                         *command = aPLU;
  174.                 }
  175.                 *vline = 0;
  176.                 return(0);
  177.         }
  178.  
  179.         if (*command == aPLU) {
  180.                 (*vline)++;
  181.                 return(0);
  182.         }
  183.  
  184.         if (*command == aPLD){
  185.                 (*vline)--;
  186.                 return(0);
  187.         }
  188.  
  189.         if (*command == aSTBM) {        /* Top & bottom margins */
  190.                 if (Parms[0] == 0) {
  191.                         Parms[0] = topmargin;
  192.                 }
  193.                 else {
  194.                         topmargin = --Parms[0];
  195.                 }
  196.  
  197.                 if (Parms[1] == 0) {
  198.                         Parms[1] = textlength;
  199.                 }
  200.                 else {
  201.                         textlength=Parms[1];
  202.                 }
  203.                 while (x < 13) {
  204.                         outputBuffer[x] = initTMarg[x];
  205.                         x++;
  206.                 }
  207.                 numberString(Parms[0], 3, outputBuffer);
  208.                 numberString(Parms[1] - Parms[0], 10, outputBuffer);
  209.                 return(x);
  210.         }
  211.  
  212.         if (*command == aSLPP) {        /* Set form length */
  213.                 while(x < FORM_LEN) {
  214.                         outputBuffer[x] = initForm[x];
  215.                         x++;
  216.                 }
  217.                 /*restore textlength, margin*/
  218.                 numberString(topmargin, 3, outputBuffer);
  219.                 numberString(textlength, 10, outputBuffer);
  220.                 return(x);
  221.         }
  222.  
  223.         if (*command == aRIS) {         /* Reset */
  224.                 PD->pd_PWaitEnabled = 253;   /* Save data! */
  225.         }
  226.  
  227.         if (*command == aSFC) {               /* Foreground colour */
  228.                           if (Parms[0] == 39)
  229.                                    Parms[0] = 30;
  230.                           if (Parms[0] > 37)
  231.                                    return(0);
  232.                           outputBuffer[x++] = '\033';
  233.                           outputBuffer[x++] = '*';
  234.                           outputBuffer[x++] = 'v';
  235.                           outputBuffer[x++] = ISOColorTable[Parms[0]-30];
  236.                           if (Parms[0] == 34)
  237.                               outputBuffer[x++] = '2';
  238.                           if (Parms[0] == 35)
  239.                               outputBuffer[x++] = '0';
  240.                           outputBuffer[x++] = 'S';
  241.                           return(x);
  242.         }
  243.         return(0);
  244. }
  245.  
  246. /* Inserts Param into output buffer */
  247. void numberString(UBYTE Param, int x, char outputBuffer[])
  248. {
  249.         if (Param > 199) {
  250.                 outputBuffer[x++] = '2';
  251.                 Param -= 200;
  252.         }
  253.         else if (Param > 99) {
  254.                 outputBuffer[x++] = '1';
  255.                 Param -= 100;
  256.         }
  257.         else {
  258.                 outputBuffer[x++] = '0'; /* always return 3 digits */
  259.         }
  260.  
  261.         if (Param > 9) {
  262.                 outputBuffer[x++] = Param / 10 + '0';
  263.         }
  264.         else {
  265.                 outputBuffer[x++] = '0';
  266.         }
  267.  
  268.         outputBuffer[x] = Param % 10 + '0';
  269. }
  270.  
  271. int ConvFunc(char *buf, char c, int flag)
  272. /* expand lf into lf/cr flag (0-yes, else no ) */
  273. {
  274.         if (c == '\014') { /* if formfeed (page eject) */
  275.                 PED->ped_PrintMode = 0; /* no data to print */
  276.         }
  277.         return(-1); /* pass all chars back to the printer device */
  278. }
  279.  
  280. int Close(union printerIO *ior)
  281. {
  282.         if (PED->ped_PrintMode) { /* if data has been printed */
  283.                 (*(PD->pd_PWrite))("\014",1); /* eject page */
  284.                 (*(PD->pd_PBothReady))(); /* wait for it to finish */
  285.                 PED->ped_PrintMode = 0; /* no data to print */
  286.         }
  287.         return(0);
  288. }
  289.  
  290.